package com.android.hidephotosplus.service;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;

import android.app.IntentService;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;

import com.android.hidephotosplus.model.ModelMedia;
import com.android.hidephotosplus.util.BitmapUtils;
import com.android.hidephotosplus.util.Config;

public class HidePhotoService extends IntentService {

	public static final String ACTION_GET_LIST_HIDDEN = "action_list_hidden";

	public HidePhotoService() {
		super("HidePhotoService");
	}

	@Override
	protected void onHandleIntent(Intent intent) {
		if (intent.getAction().equals(ACTION_GET_LIST_HIDDEN)) {
			ArrayList<ModelMedia> arrMedias = intent
					.getParcelableArrayListExtra(Config.KEY_GET_LIST_HIDDEN);
			if (arrMedias != null && arrMedias.size() > 0) {
				for (ModelMedia media : arrMedias) {
					String pathHidePhoto = media.getPathMediaHidden();
					Log.e("pathHidePhoto", pathHidePhoto);
					Bitmap bitmap = BitmapUtils.getThumbFromDisk(pathHidePhoto,
							Config.MAX_PIXELS_WIDTH, Config.MAX_PIXELS_HEIGHT);
					if (bitmap != null) {
						File fileThumb = new File(pathHidePhoto
								+ Config.EXETENSION_THUMBNAIL);
						FileOutputStream mStream;
						try {
							mStream = new FileOutputStream(fileThumb);
							bitmap.compress(Bitmap.CompressFormat.JPEG, 100,
									mStream);
							mStream.flush();
							mStream.close();
						} catch (FileNotFoundException e1) {
						} catch (IOException e) {
						}
					} else {
						Log.e("get bitmap null", "null");
					}
				}
			}

		}

	}

}
